# Maintainer: Alberto Fanjul Alonso <albfan@gnome.org>

_realname=libdazzle
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.38.0
pkgrel=1
arch=('any')
pkgdesc="A companion library to GObject and Gtk+"
depends=("${MINGW_PACKAGE_PREFIX}-glib2")
makedepends=("${MINGW_PACKAGE_PREFIX}-gtk3"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-pygobject-devel")
options=('strip' 'staticlibs')
license=("LGPL")
url="https://gitlab.gnome.org/GNOME/libdazzle"
source=("https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz"
        "0001-windows-Build-pango_font_description_to_css-on-windo.patch"
        "0002-Install-to-bin-dir.patch")
sha256sums=('e18af28217943bcec106585298a91ec3da48aa3ad62fd0992f23f0c70cd1678f'
            '9cd13af5f88036246295795f58358b07942fe6b269baa9e3b895f2d43deb3f44'
            '8585b4889cd1ce2c6a50634ff75f28a23f8d1b9ebf5f465e363e7897247ee12c')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  patch -p1 -i ${srcdir}/0001-windows-Build-pango_font_description_to_css-on-windo.patch
  patch -p1 -i ${srcdir}/0002-Install-to-bin-dir.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  meson \
    --buildtype plain \
    -Dvapi=true \
    -Dgtk_doc=true \
    ../${_realname}-${pkgver}

  ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR=${pkgdir}${MINGW_PREFIX} ninja install

  local _PRE_WIN="$(cygpath -m ${MINGW_PREFIX})"
  for pcfile in  "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/*.pc; do
    sed -s "s|${_PRE_WIN}|${MINGW_PREFIX}|g" -i "${pcfile}"
  done

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
